#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os,sys
sys.path.append("/Users/admin/Documents/stock/UGFAFAFA/code/")
import pandas as pd
from database import con,droptable

def inster(table,columns:[],df):
    if len(df.index) <= 0:
        return

    def downvalue(x):
        arr = []
        for column in columns:
            arr.append(("'%s'" % str(x[column])))
        return "("+",".join(arr)+")"
    try:
        col = ",".join(columns)
        arrs =  df.apply(downvalue,axis=1)
        for i in range(0, len(arrs), 100):
          
            values = ",".join(arrs[i:i+100].map(lambda x:str(x))) 
            sql = ("INSERT OR REPLACE INTO %s (%s) VALUES %s" % (table, col,values))
            # print(sql)
            con.execute(sql)
            con.commit()
    except Exception as e:
            print(e)
        
      


